package com.jw.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jw.system.entity.Menu;
import com.jw.system.mapper.MenuMapper;
import com.jw.system.service.MenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jw.utils.MenuTreeBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜单表 服务实现类
 * </p>
 *
 * @author jw
 * @since 2021-04-20
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public List<Menu> buildMenuTree(){
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        System.out.println(name+"------------>");
        QueryWrapper<Menu> wrapper = new QueryWrapper<>();
        wrapper.eq("type","0");
        List<Menu> rootMenu = menuMapper.getMenuListByUserName(name);
        System.out.println("aa啊啊啊啊啊啊啊啊啊啊啊");
        System.out.println(rootMenu);
        System.out.println("11111111111111111111");
        return MenuTreeBuilder.build(rootMenu);
    }

}
